<template>
	<view class="page">
		<view class="cu-bar bg-white">
			
			<view class="action">
				<image class="card" :src="card" ></image>
			</view>
		</view>
		<view class="cu-bar bg-white">
			<view class="action" >
				<image class="card" :src="cardb"></image>
			</view>
		</view>
		<view class="cu-bar bg-white">
			<view class="action" @tap="SaveImage">
				<view class="cu-btn round sure bg-blue">确认</view>
			</view>
		</view>
	<!-- 绑定 -->
	<goReg 
		ref="goReg" 
		:contentHeight="580"
	></goReg>
	</view>
</template>

<script>
	import goReg from "@/components/goReg";
	export default {
		components: {
			goReg,
		},
		data() {
			return {
				// cityPickerValueDefault: [0, 0, 1],
				// pickerText: '',
				// areaCompare:'请选择',
				// area:'请选择',
				// areaIndex:0,
				sexIndex:-1,
				sexPicker: ['男', '女'],
				workIndex:-1,
				workPicker: ['是','否'],
				basePay:'',
				realPay:'',
				age:'',
				level:'',
				card:'',
				cardb:'',
				imgList:[],
				resultData:'',
				modalName: null,
			};
		},
		onShow() {
			let param = uni.getStorageSync('cardParam') ;
			this.card = param.img1;
			this.cardb = param.img2;
		},
		methods: {
			goPage(page){
				
				uni.setStorageSync('injuryParam',{wages:this.realPay,injury_base:this.basePay,gender:this.sexIndex+1,age:this.age,
				work:this.workIndex+1,level:this.level});
				uni.navigateTo({
					url: page
				})
			},
			async SaveImage(){
				if(this.card==''||this.card=='/static/images/card.png'){
					uni.showToast({
						title: "请先选择身份证正面",
						icon: "none"
					});
					return;
				}
				if(this.cardb==''||this.cardb=='/static/images/cardb.png'){
					uni.showToast({
						title: "请先选择身份证背面",
						icon: "none"
					});
					return;
				}
				// let uId = uni.getStorageSync('userId');
				let uId = 1;
				if(uId>"0"&&uId!=undefined){
					let param = {card_image1:this.card,card_image2:this.cardb};
					// let data = await this.$http.post('fiveRisks',{city:'重庆市',wages_before:'10000',wages_real:'6000'});
					let data = await this.$http.post(
						'cardScan', //可以直接放链接(将不启用全局定义域名)
						param, 
					);
					console.log(data);
					uni.downloadFile({
						url: data,//图片地址
						success: (res) =>{
							if (res.statusCode === 200){
								uni.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success: function() {
										uni.showToast({
											title: "保存成功",
											icon: "none",
										});
										
										setTimeout(function () {
											uni.switchTab({
												url:'/pages/tabbar/tabbar-2/tabbar-2'
											})
										}, 2000);
					
										
									},
									fail: function() {
										uni.showToast({
											title: "保存失败",
											icon: "none"
										});
									}
								});
							} 
						}
					})
					return;
				}
				
				this.$refs.goReg.showModal('regModal');	
				return;
				
			}
		}
	}
</script>

<style>
	.page {
		height: 100%;
		width: 100%;
		background: #FFF;
		position: absolute;
		
	}
	.cu-bar{
		text-align: center;
		display: block;
		margin-top: 70px;
	}
	.card{
		width: 90px;
		height: 150px;
		transform: rotate(-90deg);
	}
	.sure{
		width: 150px;
		height: 40px;
	}
	.cu-list.menu>.bottom{
		position: fixed !important;
		width: 100%;
		bottom: 0;
	}
	.page.show {
		overflow: hidden;
	}
	.input{
		text-align: right;
		font-size: 12px;
	}
	
</style>
